import 'dart:convert' show json;

class SystemTreeModel {
  int? errorCode;
  String? errorMsg;
  List<SystemTreeData>? data;

  SystemTreeModel.fromParams({this.errorCode, this.errorMsg, this.data});

  factory SystemTreeModel(jsonStr) => jsonStr == null
      ? SystemTreeModel.fromParams()
      : jsonStr is String
      ? SystemTreeModel.fromJson(json.decode(jsonStr))
      : SystemTreeModel.fromJson(jsonStr);

  SystemTreeModel.fromJson(Map<String, dynamic> jsonRes) {
    errorCode = jsonRes['errorCode'];
    errorMsg = jsonRes['errorMsg'];
    data = (jsonRes['data'] as List?)
        ?.map((item) => SystemTreeData.fromJson(item))
        .toList();
  }

  @override
  String toString() {
    return '{"errorCode": $errorCode, "errorMsg": ${errorMsg != null ? json.encode(errorMsg) : 'null'}, "data": $data}';
  }
}

class SystemTreeData {
  int? courseId;
  int? id;
  int? order;
  int? parentChapterId;
  int? visible;
  bool? userControlSetTop;
  String? name;
  List<SystemTreeChild>? children;

  SystemTreeData({
    this.courseId,
    this.id,
    this.order,
    this.parentChapterId,
    this.visible,
    this.userControlSetTop,
    this.name,
    this.children,
  });

  factory SystemTreeData.fromJson(dynamic jsonRes) {
    return SystemTreeData(
      courseId: jsonRes['courseId'],
      id: jsonRes['id'],
      order: jsonRes['order'],
      parentChapterId: jsonRes['parentChapterId'],
      visible: jsonRes['visible'],
      userControlSetTop: jsonRes['userControlSetTop'],
      name: jsonRes['name'],
      children: (jsonRes['children'] as List?)
          ?.map((item) => SystemTreeChild.fromJson(item))
          .toList(),
    );
  }

  @override
  String toString() {
    return '{"courseId": $courseId,"id": $id,"order": $order,"parentChapterId": $parentChapterId,"visible": $visible,"userControlSetTop": $userControlSetTop,"name": ${name != null ? json.encode(name) : 'null'},"children": $children}';
  }
}

class SystemTreeChild {
  int? courseId;
  int? id;
  int? order;
  int? parentChapterId;
  int? visible;
  bool? userControlSetTop;
  String? name;
  List<dynamic>? children;

  SystemTreeChild({
    this.courseId,
    this.id,
    this.order,
    this.parentChapterId,
    this.visible,
    this.userControlSetTop,
    this.name,
    this.children,
  });

  factory SystemTreeChild.fromJson(dynamic jsonRes) {
    return SystemTreeChild(
      courseId: jsonRes['courseId'],
      id: jsonRes['id'],
      order: jsonRes['order'],
      parentChapterId: jsonRes['parentChapterId'],
      visible: jsonRes['visible'],
      userControlSetTop: jsonRes['userControlSetTop'],
      name: jsonRes['name'],
      children: jsonRes['children'],
    );
  }

  @override
  String toString() {
    return '{"courseId": $courseId,"id": $id,"order": $order,"parentChapterId": $parentChapterId,"visible": $visible,"userControlSetTop": $userControlSetTop,"name": ${name != null ? json.encode(name) : 'null'},"children": $children}';
  }
}
